package com.lhnstart.learn.bases.exception;

import java.util.Scanner;

/**
 * 异常作业
 *
 * @author lhn
 * @date 2023/07/23 10:55
 * @since 1.0.0
 **/
public class HomeWork01 {

    public static void main(String[] args) {

        Scanner scanner = new Scanner(System.in);
        System.out.print("请输入第一个参数:");
        String n1 = scanner.next();
        System.out.print("请输入运算符号:");
        String calculatingSigns = scanner.next();
        System.out.print("请输入第二个参数:");
        String n2 = scanner.next();

        int anInt1 = 0;
        int anInt2 = 0;
        // 判断数据格式是否正常
        try {
            anInt1 = Integer.parseInt(n1);
            anInt2 = Integer.parseInt(n2);
        } catch (NumberFormatException e) {
            System.out.println("数据格式不正确!");
        }
        if (anInt2 == 0) {
            throw new ArithmeticException("不能除0!");
        }
        if (!calculatingSigns.equals("/")) {
            throw new NullPointerException("缺少命令参数!");
        }
        System.out.println(EcmDef.cal(anInt1, anInt2));
    }

}

class EcmDef {

    public static int cal(int n1, int n2) {
        return n1 / n2;
    }

}